package com.aoyy.dao;

import java.util.List;
import java.util.ArrayList;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.aoyy.model.Product;
/**================================================================================
 * <code>ProductDaoImpl</code> class for <code>Product</code> DAO
 * @author Administrator
 * @date 2017-07-13
 * ================================================================================ */
@Repository("productDao")
@Transactional
public class ProductDaoImpl extends BaseDaoImpl<Product> implements IProductDao {
  @Override 
  @Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true) 
  public Boolean isUniqueProduct(Product product, Integer operation) {
	String hql;
	List<Object> list = new ArrayList<Object>();
	if (operation == 0) {
	  hql = "from Product where name = ?";
	  list.add(product.getName());
	} else {
	  hql = "from Product where name = ? and productId != ?";
	  list.add(product.getName());
	  list.add(product.getProductId());
	}
	if (uniqueResult(hql, list.toArray()) != null) {
	  return false;	
	}
	return true;  
  }
  
}
